package com.shijiwei.lifthelper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by sjw on 2015/12/12.
 */
public abstract class AppBaseAdapter extends BaseAdapter {

    public List<?> list;
    public LayoutInflater inflater;
    public Context context;

    public AppBaseAdapter(List<?> list, Context context) {
        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return list == null ? 0 : position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getItemView(position,convertView,parent);
    }

    public abstract View getItemView(int position, View convertView, ViewGroup parent);

    public class BaseViewHolder{
        private View convertView;

        public BaseViewHolder(View convertView) {
            this.convertView = convertView;
            convertView.setTag(this);
        }
    }
}
